﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Web;
using System.Web.Security;

namespace DreamBox.BLL.User
{
    public static class Cookies
    {
        /// <summary>
        /// 获取保存在COOKIES中的用户信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static List<string> GetCookies(HttpRequestBase request)
        {
            List<string> list = new List<string>();
            if (request.Cookies["dbox_user"] != null)
            {
                list.Add(request.Cookies["dbox_user"].Values["username"]);
                list.Add(request.Cookies["dbox_user"].Values["password"]);
            }
            return list;
        }
        /// <summary>
        /// 更新COOKIES时间期限
        /// </summary>
        /// <param name="response"></param>
        public static void Delete(HttpResponseBase response,HttpRequestBase request)
        {
            HttpCookie cookie = request.Cookies["dbox_user"];
            if (cookie != null)
            {
                cookie.Expires = DateTime.Now.AddDays(-1);
                response.Cookies.Add(cookie);
            }
        }
        /// <summary>
        /// 添加COOKIES
        /// </summary>
        /// <param name="response"></param>
        /// <param name="email"></param>
        /// <param name="password"></param>
        public static void Add(HttpResponseBase response, string email, string password)
        {
            HttpCookie cookie = new HttpCookie("dbox_user");
            cookie.Values["username"] = email;
            cookie.Values["password"] = password;
            cookie.Expires = DateTime.Now.AddDays(15);
            response.Cookies.Add(cookie);
        }
    }
}
